@extends('admin.layouts.main')
@section('header')
    @parent
    <style>
        .quoteBox{
            padding: 5px;
            margin-top: 10px;
        }
    </style>
@endsection
@section('content')
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <span class="layui-btn layui-btn-sm layui-btn-primary">期数</span>
                <div class="layui-input-inline">
                    <input class="layui-input sessionInput" type="text" placeholder="期数"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">场数</span>
                <div class="layui-input-inline">
                    <input class="layui-input numberInput" type="number" min="0" value="30" placeholder="场数"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">胜率</span>
                <div class="layui-input-inline">
                    <input class="layui-input rateInput" type="search" value="70" placeholder="胜率"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">分数</span>
                <div class="layui-input-inline">
                    <input class="layui-input scoreInput" type="number" min="0" value="4" placeholder="分数"/>
                </div>
                <span class="layui-btn layui-btn-sm layui-btn-primary">类型</span>
                <div class="layui-input-inline">
                    <select name="type" class="typeInput">
                        <option value="week">周</option>
                        <option value="month">月</option>
                        <option value="quarter" selected>三月</option>
                    </select>
                </div>
                <div class="layui-btn-group">
                    <span class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm search-btn">
                        <i class="layui-icon">&#xe615;</i> 查询
                    </span>
                </div>
            </div>
        </form>

    </blockquote>
    <div >
        <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
    </div>
    @verbatim
    <!-- 操作列 -->
    <script type="text/html" id="operTpl">
        <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="statistic">数据查看</a>
        {{# if(d.match_status == 2){ }}
        <a class="layui-btn layui-btn-primary layui-btn-radius layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-radius layui-btn-xs" lay-event="del">删除</a>
        {{# } }}
    </script>
    <script type="text/html" id="scoreTpl">
        {{# if(d.match_status == 1){ }}
        {{ d.score }}
        {{#}else if(d.match_status == 2){  }}
        比赛未结束
        {{#}else if(d.match_status == 0){ }}
        比赛已中止
        {{# } }}
    </script>
    @endverbatim
@endsection

@section('footer')
    @parent
    <script type="text/javascript">
        layui.config({
            base:'{{ asset('xman/extends') }}/'
        }).extend({
            //treetable: 'treetable-lay/treetable'
        }).use([ 'laytpl','table','form','laydate'],function () {
            var laytpl = layui.laytpl,
                table = layui.table,
                laydate = layui.laydate,
                form = layui.form;
            laydate.render({
                elem:'.sessionInput',
                type:'date',
                format:'yyyyMMdd'
            });
            tableRender();
            function tableRender() {
                var session = $('.sessionInput').val();
                var number = $('.numberInput').val();
                var rate = $('.rateInput').val();
                var score = $('.scoreInput').val();
                var type = $('.typeInput').val();
                table.render({
                    elem:'#treeTable',
                    url: "{{ url('admin/lottery/recommend') }}",
                    method: 'get',
                    where:{session:session,number:number,rate:rate,score:score,type:type},
                    page:{
                        layout:['limit', 'count', 'prev', 'page', 'next', 'skip'],
                        groups: 5
                    },
                    limit: 20,
                    limits: [10, 20, 50, 100],
                    request:{
                        pageName: 'page',
                        limitName: 'pageSize'
                    },
                    response: {
                        statusName: 'status', //数据状态的字段名称，默认：code
                        statusCode: 200, //成功的状态码，默认：0
                        msgName: 'msg', //状态信息的字段名称，默认：msg
                        countName: 'totalCount', //数据总数的字段名称，默认：count
                        dataName: 'pages' //数据列表的字段名称，默认：data
                    },
                    cellMinWidth: 95,
                    height: "full",
                    id: "treeTable",
                    cols: [[
                        {field:'session',title:'期数',align:'center',width:140,templet:function(d){
                            return d.session+"_"+d.number;
                            }},
                        {field:'nickname',title:'昵称',align:'center',width:100,templet:function (d) {
                                return "<span class='layui-btn layui-btn-xs layui-btn-primary userRecord' data-id='"+d.user_id+"'>"+d.nickname+"</span>"
                            }},
                        {field:'host',title:'主队',align:'center',width:100},
                        {field:'guest',title:'客队',align:'center',width:100},
                        {field:'balls',title:'让球',align:'center',width:60},
                        {field:'score',title:'比分',align:'center',width:100,templet:"#scoreTpl"},
                        {field:'result',title:'结果',align:'center',width:150,templet:function (d) {
                                if(d.match_status == 1){
                                    return buildResult(d.result,d.match_result)
                                }else {
                                    return buildResult(d.result,d.match_result)
                                }
                            }},
                        {field:'odds',title:'赔率',align:'center',width:60},
                        {title: '操作',templet:'#operTpl', width:200,fixed: "right", align: "left"}
                    ]]
                })
            }
            $('.search-btn').click(function () {
               tableRender();
            });
            function buildResult(result,matchResult){
                var html = "";
                if(!result){
                    return html;
                }
                if(matchResult){
                    for(var i=0;i<matchResult.length;i++){
                        matchResult[i] = parseInt(matchResult[i]);
                    }
                }
                $.each(result,function (i,e) {
                    var num = parseInt(e);
                    var resName = '';
                    switch (num){
                        case 1:
                            resName = '胜';
                            break;
                        case 2:
                            resName = "平";
                            break;
                        case 3:
                            resName = "负";
                            break;
                        case 4:
                            resName = "让胜";
                            break;
                        case 5:
                            resName = "让平";
                            break;
                        case 6:
                            resName = "让负";
                            break;
                    }
                    var color = "layui-btn-danger";
                    if($.inArray(num,matchResult) == -1){
                        color = "";
                    }
                    html += "<span class='layui-btn layui-btn-radius layui-btn-xs "+color+"'>"+resName+"</span>";
                });
                return html;
            }
            $('body').on('click','.userRecord',function () {
               var userId = $(this).attr('data-id');
               var name = $(this).text();
               openWindow('{{ url('admin/lottery/userRecord') }}?userId='+userId,name+'__推荐记录')
            });

            //工具栏监听
            table.on("tool(treeTable)",function (obj) {
                var data = obj.data;
                var layEvent = obj.event;
                switch (layEvent){
                    case 'edit':
                        edit(data.id);
                        break;
                    case 'del':
                        changeStatus(data.id,'delete');
                        break;
                    case 'statistic':
                        openWindow('{{ url('admin/lottery/statistic') }}?id='+data.user_id+'&session='+data.session,data.nickname+'__数据分析');
                        break;
                }
            });
            //编辑
            function edit(id) {
                openWindow('{{ url('admin/lottery/record/edit') }}?id='+id,'添加/编辑')
            }
            //状态修改
            function changeStatus(id,opt) {
                goConfirm('{{ url('admin/lottery/status') }}',{id:id,opt:opt},'确定该操作?',0);
            }
        })
    </script>
@endsection
